import React, { useEffect } from 'react'
import { connect } from "react-redux"
import {initRoleAction} from "@/redux/actions"
import useRequest from '../../hooks/useRequest'

function Sale(props) {
  const {getRoles} = useRequest()
  useEffect(() => {
    console.log(props);
    //发送异步请求
    // props.dispatch(initRoleAction())
    //自己发送异步，将结果放在状态机
    //先自己发送请求，获取数据，调用dispatch数据保存
    getRoles()
  }, [])
  return (
    <div>
      <h3>Sale</h3>
      <p>{props.state.roles.length}</p>
    </div>
  )
}

const mapStateToProps = (state) => {
  return {
    state:state.roleRD
  }
}
export default connect(mapStateToProps)(Sale)